package com.elective.courseselect.controller;

import com.elective.courseselect.entity.QuestionEntity;
import com.elective.courseselect.service.QuestionService;
import com.elective.courseselect.utils.PageUtils;
import com.elective.courseselect.utils.R;
import com.elective.status.StatusCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
 /**
 * 调查问卷，一条数据代表一题
 *
 * @author lee
 * @email 943204006@qq.ccom
 * @date 2021-09-04 19:22:34
 */
@RestController
@RequestMapping("courseselect/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = questionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		QuestionEntity question = questionService.getById(id);

        return R.ok().put("question", question);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody QuestionEntity question){
		questionService.save(question);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody QuestionEntity question){
		questionService.updateById(question);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		questionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    //查询性格调查问卷
    @ApiOperation("查询性格调查问卷")
    @GetMapping("/searchCharacterQuestion/{questionnaireId}")
    @Deprecated
    public R searchCharacterQuestion(@PathVariable Integer questionnaireId){
        R r = questionService.searchCharacterQuestion(questionnaireId);
        return r;
    }

     @ApiOperation("修改问卷")
     @PostMapping("/updateQuestion")
     public R updateTestPaper(@RequestBody List<QuestionEntity> questionEntity){
         questionService.updateTestPaper(questionEntity);
         return R.ok(StatusCode.OK, "修改问卷成功");
     }





 }
